<?php
/**
 * Authenticate logic for admin area
 *
 * @author     Mario Schillermann <info@rockit-flash.com>
 * @encoding   UTF-8 äöüßÖÄÜ
 * @copyright  © 2011 Mario Schillermann (info@rockit-flash.com)
 * @license    GNU GPL v2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
 * @category   Module
 * @uses       Zend_Controller_Action
 * @package    Rockitbos
 * @subpackage Controller
 * @todo
 */

class Rockitbos_WebController extends Zend_Controller_Action
{
    /**
     * Set browser title
     */
    public function init()
    {
        $this->_helper->layout->disableLayout();
        
        $this->view->headTitle('RockitBOS');
        $this->view->headTitle()->setSeparator(' - ');
    }
    /**
     * Login logic
     *
     * @return void
     */
    public function indexAction()
    {
        try {
            $auth = Zend_Auth::getInstance();

            if ($this->_request->set == 'logout') {
                /** Remove identity */
                $auth->clearIdentity();
                /** redirect to login form */
                $this->_redirect('/rockitbos');
            } else if ($auth->hasIdentity()) {

                $app = $this->_request->app;
                $tab = $this->_request->tab;
                $do = $this->_request->do;

                if (!empty($app)) {

                    $layout = Zend_Layout::getMvcInstance();
                    $layout->setLayoutPath(
                        'application/modules/rockitbos/views/scripts');
                    $layout->setLayout('app');

                    if(empty($tab)) {
                        $tab = 'app';
                    }
                    if(empty($do)) {
                        $do = 'index';
                    }

                    $this->_forward($do, $tab, $app);

                    $front = $this->getFrontController();
                    $front->registerPlugin(new App_Plugin_Acl());
            } else {
                $this->_forward('index', 'dashboard', 'dashboard');
            }
        } else {
            // show login form
            $this->_forward('index', 'login', 'login');
        }
        } catch (Zend_Exception $e) {
            error_log(print_r($e, true));
        }
    }
}